package com.wintrisstech.iaroc.irobot;

import java.io.IOException;

public class IRobotCreateExtendedInterface extends IRobotCreateInterface implements IRobotCreateExtendedConstants {
    protected int velocity;

    public IRobotCreateExtendedInterface() throws IOException {
        super();
    }
    
    public IRobotCreateExtendedInterface(IRobotCreateSerialConnection serialConnection, IRobotCreateSensorState sensorState) throws IOException {
        super(serialConnection, sensorState);
        velocity = IRobotCreateConstants.DRIVE_MAX_VELOCITY / 2;
    }

    public void goBackward() throws IOException {
        drive(-velocity, IRobotCreateConstants.DRIVE_STRAIGHT);
    }

    public void goForward() throws IOException {
        drive(velocity, IRobotCreateConstants.DRIVE_STRAIGHT);
    }
    
    public void driveStop() throws IOException {
        drive(0, 0);
    }
    
    public void setVelocity(int velocity) {
        System.out.print("setVelocity: ");
        System.out.println(velocity);
        this.velocity = Math.max(0, Math.min(velocity, IRobotCreateConstants.DRIVE_MAX_VELOCITY));
    }

    public void spinLeft() throws IOException {
        drive(velocity, IRobotCreateConstants.DRIVE_TURN_IN_PLACE_COUNTER_CLOCKWISE);
    }

    public void spinRight() throws IOException {
        drive(velocity, IRobotCreateConstants.DRIVE_TURN_IN_PLACE_CLOCKWISE);
    }

}
